package com.softserveinc.moviedbapp.application;

import android.content.Context;
import android.widget.Toast;

import com.softserveinc.moviedbapp.R;

public class PreferenceInputValidator {

	public static boolean checkNumericalInput(final Context context, final Object newValue, final int minRange,
			final int maxRange) {
		if (!newValue.toString().equals("") && newValue.toString().matches("\\d*")) {

			try {
				int numOfMovies = Integer.valueOf((String) newValue);
				if (numOfMovies >= minRange && numOfMovies <= maxRange) {
					return true;
				}
			} catch (NumberFormatException ex) {

			}
		}

		Toast.makeText(context, newValue + " " + context.getResources().getString(R.string.is_an_invalid_number),
				Toast.LENGTH_SHORT).show();
		return false;

	}

}
